package com.cgly.medical.controller;


import com.cgly.medical.domain.China;
import com.cgly.medical.domain.Material;
import com.cgly.medical.service.MaterialService;
import com.cgly.medical.util.Msg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/materials")
@CrossOrigin  //解决跨域问题
public class MaterialController {

    @Resource
    private MaterialService materialService;

    //查询所有必备材料数据
    @GetMapping("selectAll/{page}/{limit}")
    public Msg getAllMaterial(@PathVariable Integer page,@PathVariable Integer limit){
        Msg msg=materialService.getAllMaterial(page,limit);
        return msg;
    }


    //条件查询对应的必备材料信息
    @PostMapping("getsomeMaterial/{page}/{limit}")
    public Msg getsomeMaterial(@PathVariable Integer page,@PathVariable Integer limit,@RequestBody(required = false) Material material){
        material.setPn(page);
        material.setSize(limit);
            Msg msg =materialService.selectSomeMaterial(material);
            return msg;

    }

    //根据id查询材料
    @GetMapping("getmaterial/{id}")
    public Msg getMaterialById(@PathVariable Integer id){
        Msg msg = materialService.selectMaterialById(id);
        return msg;
    }

    @PostMapping("add")
    public Msg addMaterial(@RequestBody(required = false) Material material){
        Msg msg = materialService.insertMaterial(material);
        return msg;
    }

    @PostMapping("update")
    public Msg updateMaterial(@RequestBody(required = false) Material material){
        Msg msg = materialService.updateMaterial(material);
        return msg;
    }

    @DeleteMapping("delete")
    public Msg deleteMaterialById(@RequestBody(required = false) String id){
        int ids = Integer.parseInt(id);
        Msg msg = materialService.deleteMaterialById(ids);
        return msg;
    }
}
